﻿using BaseNet.Core.SeedData.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseNet.Core.SeedData
{
    /// <summary>
    /// 系统菜单种子数据
    /// 菜单数据直接存储于cs文件中，保持开发版本与正式版本一致性
    /// </summary>
    public static class SysMenuSeedData
    {
        /// <summary>
        /// 获取树菜单
        /// </summary>
        /// <returns></returns>
        public static List<SysMenuDto> GetTreeList(List<SysMenuDto> list)
        {
            return BuildTreeList(list);
        }

        /// <summary>
        /// 获取普通单列表
        /// </summary>
        /// <returns></returns>
        public static List<SysMenuDto> GetList()
        {
            var list = new List<SysMenuDto>();
            /*******首页******************/
            list.Add(new SysMenuDto()
            {
                Id = "88b3a6fb10c4808efcfdb8731635ec6b",
                Title = "首页",
                Icon = "layui-icon layui-icon-console",
                Type = 1,
                OpenType = "_iframe",
                Href = "view/console/console.html",
                PId = "0"
            });

            /*******系统管理******************/
            list.Add(new SysMenuDto()
            {
                Id = "7fed1b43013a749a84584a9ee6b955d7",
                Title = "系统管理",
                Icon = "layui-icon layui-icon-set-fill",
                Type = 0,
                OpenType = "",
                Href = "",
                PId = "0",
            });
            list.Add(new SysMenuDto()
            {
                Id = "d629c735d164ac03c6a92bbb0133d972",
                Title = "系统角色",
                Icon = "",
                Type = 1,
                OpenType = "_iframe",
                Href = "view/system/role/main.html",
                PId = "7fed1b43013a749a84584a9ee6b955d7"
            });
            list.Add(new SysMenuDto()
            {
                Id = "a9a1e4faecdee5e96c605caf2dd1c542",
                Title = "系统用户",
                Icon = "",
                Type = 1,
                OpenType = "_iframe",
                Href = "view/system/user/main.html",
                PId = "7fed1b43013a749a84584a9ee6b955d7"
            });
            list.Add(new SysMenuDto()
            {
                Id = "4b50250c9ce7cce422b85ffe8b0b3f76",
                Title = "数据字典",
                Icon = "",
                Type = 1,
                OpenType = "_iframe",
                Href = "view/system/dict/main.html",
                PId = "7fed1b43013a749a84584a9ee6b955d7"
            });

            return list;
        }

        /// <summary>
        /// 构建树列表
        /// </summary>
        /// <param name="list"></param>
        /// <param name="pId"></param>
        /// <returns></returns>
        private static List<SysMenuDto> BuildTreeList(List<SysMenuDto> list, string pId = "0")
        {
            var treeList = new List<SysMenuDto>();
            var tempList = list.FindAll(o => o.PId == pId);
            foreach (var item in tempList)
            {
                item.Children = BuildTreeList(list, item.Id);
                treeList.Add(item);
            }
            return treeList;
        }
    }
}
